<script type="text/javascript" src="__STATIC__/uploadify/jquery.uploadify.min.js"></script>
<!-- <script type="text/javascript" src="__ADDONROOT__/script/UploadImages.js"></script> -->
<link rel="stylesheet" href="__ADDONROOT__/style/UploadFiles.css">
    <input type="file" id="upload_file_{$name}">
    <input type="hidden" name="{$name}" value="{$valStr}" class="icon {$name}" />
    <div class="upload-file-box">
        <notempty name="valArr">
             <volist name="valArr" id="vo">
                <div class="upload-pre-file" data-id="{$vo.id}">
                    <span class="upload_icon_all"></span>
                    <span>{$vo.name}</span>
                    <span class="iconfont icon-cancel cancel-{$id}"></span>
                </div>
             </volist>
        </notempty>
    </div>
<script type="text/javascript">
    //上传图片
    $(function(){
        /* 初始化上传插件*/
        $("#upload_file_{$name}").uploadify({
            "height"          : 30,
            "swf"             : "__STATIC__/uploadify/uploadify.swf",
            "fileObjName"     : "download",
            "buttonText"      : "上传附件",
            "uploader"        : "{:U('File/upload',array('session_id'=>session_id()))}",
            'fileTypeExts'    : '*.pdf; *.doc; *.docx; *.xls; *.xlsx; *.ppt; *.pptx',
            "width"           : 120,
            'removeTimeout'   : 1,
            "onUploadSuccess" : uploadFile{$name},
            'onFallback' : function() {
                alert('未检测到兼容版本的Flash.');
            }
        });
        $(".upload-file-box").on('click', '.cancel-{$id}', function(event) {
            event.preventDefault();
            $(this).parent().remove();
            picsbox = $("#upload_file_{$name}").siblings('.upload-file-box');
            picArr = [];
            for (var i = 0; i < picsbox.children().length ; i++) {
                picArr.push(picsbox.children('.upload-pre-file:eq('+i+')').attr('data-id'));
            };
            picStr = picArr.join(',');
            $('.icon.{$name}').val(picStr);
        });
    })
    function uploadFile{$name}(file, data){
        var data = $.parseJSON(data);
        var src = '';
        if(data.status){
            src = data.url || '__ROOT__' + data.path;
            upload_img = "<div class='upload-pre-file' data-id=\""+data.id+"\"><span class=\"upload_icon_all\"></span><span>"+data.info+"</span><span class='iconfont icon-cancel cancel-{$id}'></span></div>";
            picsbox = $("#upload_file_{$name}").siblings('.upload-file-box');
            picsbox.append(upload_img);
            picArr = [];
            for (var i = 0; i < picsbox.children().length ; i++) {
                picArr.push(picsbox.children('.upload-pre-file:eq('+i+')').attr('data-id'));
            };
            console.log(picArr);
            picStr = picArr.join(',');
            $('.icon.{$name}').val(picStr);
        } else {
            updateAlert(data.info);
            setTimeout(function(){
                $('#top-alert').find('button').click();
                $(that).removeClass('disabled').prop('disabled',false);
            },1500);
        }
    }
</script>